
/**
 * Created by wyt on 17-5-17.
 */
$.fn.serializeJson = function () {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function () {
        if (o[this.name]) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};



function parasDate(date) {
    if(date == null || date == '' || date == undefined){
        return '';
    }
    if (date instanceof Date) {
        return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
    }
    var d = new Date(date);
    return d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
}

function getCookie (name)
{
    var cookieValue = "";
    var search = name + "=";
    if (document.cookie.length > 0)
    {
        offset = document.cookie.indexOf (search);
        if (offset != -1)
        {
            offset += search.length;
            end = document.cookie.indexOf (";", offset);
            if (end == -1)
                end = document.cookie.length;
            cookieValue = unescape (document.cookie.substring (offset, end))
        }
    }
    return cookieValue;
}


//方法-手机号验证
var _fun_check_moblie = function(_moblie) {
 if(!_moblie){
     return false;
 }
 var __pattern = /^(13[0-9]|17[0-9]|14[5|7]|15[0-9]|18[0-9])\d{8}$/;
 return _moblie.match(__pattern);
}
//方法-邮箱验证
var _fun_check_email = function(_email) {
 if(!_email){
     return false;
 }
 var __pattern = /^[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?$/;
 return _email.match(__pattern);
}

// 身份证号码验证
var _fun_check_id_code = function (_id_code) {
    if (!_id_code) {
        return false;
    }
    var __pattern = "";
    if (_id_code.length == 15) {
        __pattern = /^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{2}[0-9Xx]$/;
    } else if (_id_code.length == 18) {
        __pattern = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
    }else{
        return false;
    }
    return _id_code.match(__pattern);
}
//获取字符串长度
var _get_str_length = function(str) {
	  return str.replace(/[\u0391-\uFFE5]/g,"aa").length;  //先把中文替换成两个字节的英文，在计算长度
};

//判断对象是否是字符串
var _is_string = function(obj){   
  return Object.prototype.toString.call(obj) === "[object String]";  
}  


//判断字符串是否含有汉字
var _check_chinese = function(obj) {
	if (/.*[\u4e00-\u9fa5]+.*$/.test(obj)) {
		return false;
	}
	return true;
} 	

//校验是否含有特殊字符
var _check_special_characterst = function(obj)
{
     var re =  /^[0-9a-zA-Z]*$/g;  //判断字符串是否为数字和字母组合     //判断正整数 /^[1-9]+[0-9]*]*$/  
     if (!re.test(obj))
    {
        return false;
     }else{
    return true;
     }
}

//Base64的编码与解码转的最优方案
function utf8_to_b64(str) {
    return window.btoa(unescape(encodeURIComponent(str)));
}

function b64_to_utf8(str) {
    return decodeURIComponent(escape(window.atob(str)));
}

//替换base64等号
function replaceBase64(str){
	 if(str.lastIndexOf("=")!=-1){
		 str = str.substring(0,str.length-1);
	  }else{
		  return str;
	  }   
	    return replaceBase64(str);    
	}


function delCookie(name){
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval=getCookie(name);
	if(cval!=null)
	document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
Array.prototype.contains = function(val)
{
    for (var i = 0; i < this.length; i++)
    {
        if (this[i] == val)
        {
            return true;
        }
    }
    return false;
};

var wei_xin_arr = new Array(0,1,4,7,10,11,12,13,100);
var zhi_fu_bao_arr = new Array(3,5,6,14,15,101);
